<div class="panel-group" id="accordion">
  <div class="panel">

    <header>
      <table class="table table-hover">
        <!--type-->
        <% unless resource.class.name.blank? %>
          <tr>
            <td><span><%= t('document.info.type') %></span></td>
            <td><%= t("document.info.types." + resource.class.name.downcase, :default => resource.class.name) %></td>
          </tr>
        <% end %>

        <!-- version (for SCORM packages, ...) -->
        <% if resource.respond_to?(:resource_version) and !resource.resource_version.blank? %>
          <tr>
            <td><span><%= t('document.info.version') %></span></td>
            <td><%=resource.resource_version%></td>
          </tr>
        <% end %>
        
        <!--description-->
        <% unless resource.description.blank? %>
          <tr>
            <td><span><%= t('document.info.description') %></span></td>
            <td><%= truncate(resource.description, :length => 400) %></td>
          </tr>
        <% end %>
        
        <!--tags-->
        <% unless resource.tag_list.blank? %>
          <tr>
            <td><span><%= t('document.info.tags') %></span></td>
            <td>
              <ul class="tagit-suggestions">
                <% resource.tag_list.each do |tag| %>
                <li class="tagit-choice">
                  <%= link_to tag, search_path(:q => tag) %>
                </li>
                <% end %>
              </ul>
            </td>
          </tr>
        <% end %>

        <!--author/owner-->
        <% unless resource.original_author_name.nil? %>
          <% unless resource.linked? %>
            <!-- Documents -->
            <!-- author -->
            <tr>
              <td><span><%=t('document.info.author')%></span></td>
              <td>
                <% if resource.original_author.nil? %>
                  <%= link_to(resource.author.name, resource.author.subject) %>
                <% else %>
                  <%= resource.original_author_name %>
                <% end %>
              </td>
            </tr>
            <!-- owner -->
            <% unless  resource.author.nil? or resource.original_author.nil? %>
              <tr>
                <td><span><%=t('activity_object.author_uploaded_by')%></span></td>
                <td>
                  <%= link_to(resource.author.name, resource.author.subject) %>
                </td>
              </tr>
            <% end %>
          <% else %>
            <!-- Links -->
            <!-- author -->
            <% unless resource.original_author.nil? %>
              <tr>
                <td><span><%=t('document.info.author')%></span></td>
                <td>
                  <%= resource.original_author_name %>
                </td>
              </tr>
            <% end %>
            <!-- owner -->
            <% unless resource.author.nil? %>
              <tr>
                <td><span><%=t('document.info.linked_by')%></span></td>
                <td>
                  <%= link_to(resource.author.name, resource.author.subject) %>
                </td>
              </tr>
            <% end %>
          <% end %>
        <% end %>

        <% if resource.should_have_license? %>
          <!--license-->
          <% unless resource.license.nil? %>
            <tr>
              <td><span><%= t('document.info.license') %></span></td>
              <td>
                <%= resource.license_name %>
              </td>
            </tr>
          <% end %>
          <!--license attribution-->
          <% unless resource.license_attribution.nil? or resource.license.nil? or !resource.license.requires_attribution? %>
            <tr>
              <td><span><%= t('document.info.license_attribution') %></span></td>
              <td>
                <%= resource.license_attribution %>
              </td>
            </tr>
          <% end %>
        <% end %>

        <!--contributors-->
        <% if resource.respond_to?("contributors") and !resource.contributors.blank? %>
          <tr>
            <td><span><%= t('excursion.contributors.name').capitalize %></span></td>
            <td>
              <% resource.contributors.uniq.each_with_index do |c,index| %>
                <% unless index==0 %>
                  ,
                <% end %>
                <%= link_to c.name, c.subject %>
              <%end%>
            </td>
          </tr>
        <%end%>

      </table>
    </header>

    <div class="panel-body">
      <div id="collapseInfo" class="panel-collapse collapse">
        <table class="table table-hover">
            <!--language-->
            <% unless resource.readable_language.blank? %>
              <td><span><%= t('lang.title').capitalize %></span></td>
              <td><%= resource.readable_language %></td>
            <% end %>
          </tr>

          <% if resource.respond_to?("attachment") and !resource.attachment.blank? %>
           <tr>
            <td><span><%= t('excursion.actions.attachment') %></span></td>
          <td>
            <a href="/excursions/<%= resource.id %>/attachment"><%= resource.get_attachment_name %></a>
           <tr>
          <% end %>
          <tr>
            <!--date-created-->
            <td><span><%= t('document.info.date.created_at') %></span></td>
            <td><%= I18n.localize resource.created_at, :format => :long %></td>
          </tr>
          <tr>
            <!--date-upload-->
            <td><span><%= t('document.info.date.updated_at') %></span></td>
            <td><%= I18n.localize resource.updated_at, :format => :long %></td>
          </tr>
          <tr>
            <!--size-->
            <% if resource.respond_to?("file") and !resource.file.nil? and resource.respond_to?("file_file_size") and !resource.file_file_size.blank? %>
              <td><span><%= t('document.info.size') %></span></td>
              <td><%= number_to_human_size resource.file_file_size %></td>
            <%end%>
          </tr>
        </table>
      </div>
    </div>

    <div class="panel-footer">
      <a class="expand" data-toggle="collapse" data-parent="#accordion" href="#collapseInfo">
        <span id="showingMore" class="showMore accordion-toggle btn btn-secundary collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseInfo" title="<%=t('excursion.actions.show_more')%>" status="collapsed"><%=t('excursion.actions.show_more')%></span>
      </a>

      <!--metadata-->
      <% displayMetadata = resource.respond_to?("metadata") %>
      <% if displayMetadata %>
        <button href="#MetadataModal" id="showMeta" data-toggle="modal" class="btn btn-secundary">
          <%=t('excursion.actions.show_meta')%>
        </button>
      <%end%>

      <!--Views and Likes-->
      <div class="viewsAndCount">
        <div class="views">
          <%=resource.visit_count.to_s%>
          <span><%=t('follow.views')%></span>
        </div>
        <%unless resource.post_activity.nil?%>
          <div class="like">
            <div class="count"><%=resource.post_activity.likes.count.to_s%></div>
            <%= link_like(resource.post_activity)%>
          </div>
        <%end%>
      </div>
    </div>

  </div>
</div>

<% if displayMetadata %>
  <div id="MetadataModal" class="modal fade">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">
            <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
          </button>
          <h3 id="myMetadataLabel">
            <%= t('excursion.modal.metadata_title') %>
          </h3>
        </div>

        <div class="modal-body">
          <ul class="metadatalist">
            <%resource.metadata.each do |key, value| %>
              <%unless value.blank?%>
                <li>
                  <span class="metadatalistkey"><%=key%>:</span>
                  <span class="metadatalistkey2"><%=value%></span>
                </li>
              <%end%>
            <%end%>
            <%if resource.class.name == "Excursion" %>
              <li>
                <span class="metadatalistkey"><%=t("metadata.access_lom")%>:</span>
                <span class="metadatalistkey2"><a target="_blank" href="<%=ao_object_metadata_path(resource)%>"><%=Vish::Application.config.full_domain + ao_object_metadata_path(resource)%></a></span>
              </li>
            <%end%>
          </ul>
        </div>
      </div>
    </div>
  </div>
<% end %>

<% content_for :javascript do %>
  $("#showingMore").click(function(e){
    if($("#showingMore").attr("status")==="expanded"){
      $("#showingMore").html('<%=t("excursion.actions.show_more")%>');
      $("#showingMore").attr("title", "<%=t('excursion.actions.show_fewer')%>");
      $("#showingMore").attr("status", "collapsed");
    } else {
      $("#showingMore").html('<%=t('excursion.actions.show_fewer')%>');
      $("#showingMore").attr("title", "<%=t("excursion.actions.show_more")%>");
      $("#showingMore").attr("status", "expanded");
    }
  });
<%end%>
